<!DOCTYPE html>
<html>
<head>
    {include file="_Fragment/meta" /}
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
    <link rel="stylesheet" href="/static/pear/admin/css/other/console1.css" />
</head>
<body class="pear-container">

<div class="layui-row layui-col-space10">
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">总学习时长(H)</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value1">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">Moments(H)</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value2">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">Offline Session(H)</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value3">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">E-Learning(H)</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value4">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">轻学堂(H)</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value5">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">直播课(H)</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value7">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">积分</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value8">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="layui-row layui-col-space1">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="reload">
                <div class="layui-form-item">

                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <ul id="tree" class="dtree" data-id="0"></ul>
                        </div>
                    </div>

                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="time" id="date" placeholder="时间段" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="key" placeholder="工号|姓名" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item layui-inline">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                            <i class="layui-icon layui-icon-search"></i>
                            查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md">
                            <i class="layui-icon layui-icon-refresh"></i>
                            重置
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="user-table" lay-filter="user-table"></table>
        </div>
    </div>
</div>


<script type="text/html" id="user-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="import">
        <i class="layui-icon layui-icon-file"></i>
        导入
    </button>
</script>

<script type="text/html" id="user-bar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="view"><i class="layui-icon layui-icon-search"></i></button>
</script>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['table', 'form', 'jquery','common', 'dtree', 'laydate', 'count'], function() {
        let table = layui.table;
        let form = layui.form;
        let dtree = layui.dtree;
        let laydate = layui.laydate;
        let $ = layui.jquery;
        let common = layui.common;
        let count = layui.count;

        dtree.render({
            elem: "#tree",
            initLevel: "1",
            method: 'get',
            url: "/Members/getDepartment",
            select: true,
            selectTips: '部门',
        });

        laydate.render({
            elem: '#date'
            ,range: true //或 range: '~' 来自定义分割字符
            ,trigger: 'click'
            ,type: 'date'
        });

        let cols = [
            [
                {
                    title: '姓名',
                    field: 'name',
                    align: 'center',
                    fixed: 'left',
                },
                {
                    title: '工号',
                    field: 'carolid',
                    align: 'center',
                    fixed: 'left',
                },
                {
                    title: 'Division',
                    field: 'division',
                    align: 'center',
                },
                {
                    title: '部门',
                    field: 'department_name',
                    align: 'center',
                },
                {
                    title: 'Moments(S)',
                    field: 'moments',
                    align: 'center',
                },
                {
                    title: 'Offline Session(S)',
                    field: 'learnnow',
                    align: 'center',
                },
                {
                    title: 'E-Learning(S)',
                    field: 'learning',
                    align: 'center',
                },

                {
                    title: '轻学堂(S)',
                    field: 'qxt',
                    align: 'center',
                },
                {
                    title: '直播课(S)',
                    field: 'live',
                    align: 'center',
                },
                {
                    title: '总学习时长(S)',
                    field: 'total',
                    align: 'center',
                },
                {
                    title: '操作',
                    toolbar: '#user-bar',
                    align: 'center',
                }
            ]
        ]

        table.render({
            elem: '#user-table',
            url: '/MembersTotal/load',
            page: {layout:['count', 'prev', 'page', 'next', 'skip']},
            limit: 5,
            cols: cols,
            //skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter',{
                title: '导出' //标题
                ,layEvent: 'export' //事件名，用于 toolbar 事件中使用
                ,icon: 'layui-icon-export' //图标类名
            }]
        });
        form.on('submit(user-query)', function(data) {
            table.reload('user-table', {
                where: data.field
                ,page: {
                    curr: 1, //重新从第 1 页开始
                    layout:['count', 'prev', 'page', 'next', 'skip']
                }
                ,limit: 5,
            })
            return false;
        });

        table.on('tool(user-table)', function(obj) {
            if (obj.event === 'view') {
                window.view(obj);
            }
        });


        table.on('toolbar(user-table)', function(obj) {
            if (obj.event === 'import') {
                window.import();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'export') {
                window.export();
            }
        });

        window.view = function(obj) {
            parent.layui.admin.addTab(obj.data.userid, obj.data.name+"员工学习详情", '/MembersTotal/qxt?userid='+obj.data.userid)
        }


        window.import = function() {
            layer.open({
                type: 2,
                title: '导入',
                shade: 0.1,
                area: [common.isModile()?'100%':'900px', common.isModile()?'100%':'600px'],
                content: '/MembersTotal/import'
            });
        }

        // 数据导出
        window.export = function() {
            var field = form.val('reload');
            layer.confirm('确定要导出员工数据吗?', {
                icon: 3,
                title: '提示'
            }, function(index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: "/MembersTotal/export",
                    data:{key:field.key, tree_select_nodeId:field.tree_select_nodeId, time:field.time},
                    dataType: 'json',
                    type: 'post',
                    success: function(result) {
                        layer.close(loading);
                        if (result.status == 0) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 2000
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }
                })
            });
        };

        window.refresh = function(param) {
            table.reload('user-table');
        }


        let moments = 0;
        let learnnow = 0;
        let learning = 0;
        let qxt = 0;
        let live = 0;

        $.ajax({
            url: "/MembersTotal/getCount",
            dataType: 'json',
            type: 'post',
            success: function(res) {
                moments = res.data.moments;
                learnnow = res.data.learnnow;
                learning = res.data.learning;
                live = res.data.live;

                count.up("value2", {
                    time: 4000,
                    num: res.data.moments,
                    bit: 2,
                    regulator: 50
                })

                count.up("value3", {
                    time: 4000,
                    num: res.data.learnnow,
                    bit: 2,
                    regulator: 50
                })

                count.up("value4", {
                    time: 4000,
                    num: res.data.learning,
                    bit: 2,
                    regulator: 50
                })

                count.up("value7", {
                    time: 4000,
                    num: res.data.live,
                    bit: 2,
                    regulator: 50
                })
                count.up("value8", {
                    time: 4000,
                    num: res.data.integral,
                    regulator: 50
                })
            }
        })


        $.ajax({
            url: "/MembersTotal/getQxt",
            dataType: 'json',
            type: 'post',
            success: function(res) {
                qxt = res.data.qxt;
                count.up("value5", {
                    time: 4000,
                    num: res.data.qxt,
                    bit: 2,
                    regulator: 50
                })

                count.up("value1", {
                    time: 4000,
                    num: Number(moments) + Number(learnnow) + Number(learning) + Number(live) + Number(qxt),
                    bit: 2,
                    regulator: 50
                })
            }
        })
    })
</script>
</body>
</html>
